require 'net/http'
require 'rubygems'
require 'xmlsimple'

class DiscountAir < ActiveRecord::Base
	
	APIKEY = "96876bf07a7750412d7d7ec500a4ef4842a46cf2"
	def self.search(q)
		query = URI.escape(q, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
				
		url = 'http://apis.daum.net/tour/HotelK?apikey='+APIKEY+'&output=xml&query='+ query
		
		xml_data = Net::HTTP.get_response(URI.parse(url)).body
		
		data = XmlSimple.xml_in(xml_data);
		
		return data
	end	
end